#! /bin/bash
gitpath=$(which git);
javapath=$(which java);
echo $gitpath;
echo $javapath;
echo "当前目录:$PWD";
echo "当前安装..";
echo "设备id: $1";
echo "门店id: $2";
echo "安装服务中...";
touch /etc/systemd/system/iot.service
echo "[Unit]" > /etc/systemd/system/iot.service
echo "Description=iot" >> /etc/systemd/system/iot.service
echo "After=syslog.target" >> /etc/systemd/system/iot.service
echo "[Service]" >> /etc/systemd/system/iot.service
echo "Type=simple" >> /etc/systemd/system/iot.service
echo "ExecStart=$SHELL $PWD/start.sh" >> /etc/systemd/system/iot.service
echo "[Install]" >> /etc/systemd/system/iot.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/iot.service

touch $PWD/start.sh
echo "#! /bin/bash" > $PWD/start.sh
echo "$javapath -jar $PWD/iot-check.jar $1 $2 &" >> $PWD/start.sh
echo "while true" >> $PWD/start.sh
echo "do" >> $PWD/start.sh
echo "$gitpath --git-dir=$PWD/.git pull" >> $PWD/start.sh
echo "sleep 80000" >> $PWD/start.sh
echo "systemctl restart iot" >> $PWD/start.sh
echo "done" >> $PWD/start.sh
echo "开机启动....";

systemctl enable iot
systemctl stop iot
echo "启动中...";
systemctl start iot
echo "启动完成";
echo "安装成功.";

